//
//  TuShangTableViewCell.m
//  cityCar
//
//  Created by 常宽 on 14/10/31.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "TuShangTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface TuShangTableViewCell ()

@property (nonatomic, retain)UIImageView *myImageview;
@property (nonatomic, retain)UILabel *name;
@property (nonatomic, retain)UILabel *photoCount;
@end

@implementation TuShangTableViewCell

- (void)dealloc
{
    [_tuShangDic release];
    [_myImageview release];
    [_name release];
    [_photoCount release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self= [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.myImageview = [[UIImageView alloc]init];
        [self.contentView addSubview:_myImageview];
        [_myImageview release];
        
        self.name = [[UILabel alloc]init];
        [self.myImageview addSubview:_name];
        [_name release];
        
        self.photoCount = [[UILabel alloc]init];
        [self.myImageview addSubview:_photoCount];
        [_photoCount release];
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.myImageview.frame = self.contentView.bounds;
    self.myImageview.backgroundColor = [UIColor whiteColor];
    _myImageview.clipsToBounds = YES;
    _myImageview.contentMode = UIViewContentModeScaleAspectFill;
    
    CGFloat w = [_name superview].frame.size.width;
    CGFloat h = [_name superview].frame.size.height;
    self.name.frame = CGRectMake(0, h - 20, w - 60, 20);
    self.name.font = [UIFont systemFontOfSize:15];
    self.name.lineBreakMode = NSLineBreakByTruncatingTail;
    [self.name setBackgroundColor:[UIColor clearColor]];
    [self.name setTextColor:[UIColor whiteColor]];
    
    self.photoCount.frame = CGRectMake(w - 40, h - 20, 40, 20);
    self.photoCount.font = [UIFont systemFontOfSize:15];
    [self.photoCount setBackgroundColor:[UIColor clearColor]];
    self.photoCount.textAlignment = NSTextAlignmentRight;
    [self.photoCount setTextColor:[UIColor whiteColor]];
}

- (void)setTuShangDic:(NSDictionary *)tuShangDic
{
    if (tuShangDic != _tuShangDic) {
        [_tuShangDic release];
        _tuShangDic = [tuShangDic retain];
    }
    NSURL *url = [NSURL URLWithString:[_tuShangDic objectForKey:@"cover"]];
    [_myImageview sd_setImageWithURL:url];
    [_name setText:[_tuShangDic objectForKey:@"name"]];
    [_photoCount setText:[NSString stringWithFormat:@"%@张", [_tuShangDic objectForKey:@"photoCount"]]];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
